//
//  FPTrailerTableViewController.m
//  FilmParadise
//
//  Created by lanou3g on 15/7/18.
//  Copyright (c) 2015年 DLYgroup. All rights reserved.
//

#import "FPTrailerTableViewController.h"
#import "FPTrailerTableViewCell.h"
#import "FPPredictVidio.h"
#import "MoviePlayerViewController.h"
#import "FPPredictVidio.h"

@interface FPTrailerTableViewController ()


@end

@implementation FPTrailerTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"预告片&拍摄花絮";
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _videoArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return kImageH(110);
}

#pragma mark - 返回cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"cell";
    [tableView registerClass:[FPTrailerTableViewCell class] forCellReuseIdentifier:cellIdentifier];
    FPTrailerTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
    
    NSMutableArray * array = [NSMutableArray array];
    [_videoArray enumerateObjectsUsingBlock:^(NSDictionary *dic, NSUInteger idx, BOOL *stop) {
        FPPredictVidio *model = [FPPredictVidio predictVideoWithDictionary:dic];
        [array addObject:model];
    }];
    
    FPPredictVidio *model = array[indexPath.row];
    
    [cell.videoImageView sd_setImageWithURL:[NSURL URLWithString:model.image] placeholderImage:[UIImage imageNamed:@"2.jpg"] completed:nil];
    cell.filmNameLabel.text = [NSString stringWithFormat:@"%@\n",model.title];
    NSInteger hour = model.length / 60;
    NSInteger minute = model.length % 60;
    cell.filmTimeLabel.text = [NSString stringWithFormat:@"%ld分%ld秒",hour,minute];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    MoviePlayerViewController *movieVC = [[MoviePlayerViewController alloc] init];
    FPPredictVidio *model = self.videoArray[indexPath.row];
    movieVC.mp4_url = model.url;
    [self.navigationController pushViewController:movieVC animated:YES];
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
